package com.util;

import org.apache.commons.lang3.time.DateUtils;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 * @author :Administrator
 * @description: TODO edit class Description
 * @create date: 2021/11/12 11:11
 */
public class DateUtil extends DateUtils {

    public static Date getCurrentTime(){
        return new Date();
    }
    public static Date getStartNormalizeDay(Date date){
        return setTime(date, 0, 0, 0);
    }

    public static Date getEndNormalizeDay(Date date){
        return setTime(date, 23, 59, 59);
    }

    public static Date getStartNormalizeDay(Date date,int add){
        return setTime(addDays(date,add), 0, 0, 0);
    }

    public static Date getEndNormalizeDay(Date date,int add){
        return setTime(addDays(date,add), 23, 59, 59);
    }

    public static Date setTime(Date baseDate, int hourOfDay, int min, int sec) {
        if (baseDate == null) {
            return null;
        }

        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime(baseDate);
        cal.set(Calendar.HOUR_OF_DAY, hourOfDay);
        cal.set(Calendar.MINUTE, min);
        cal.set(Calendar.SECOND, sec);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();
    }
}
